package router

import (
	"backend/app/web/api"
	_ "backend/docs"
	"backend/middlewares"
	"backend/utils/logger"

	"github.com/gin-gonic/gin"
	swaggerfiles "github.com/swaggo/files"
	gs "github.com/swaggo/gin-swagger"
)

func SetupRouter(mode string, sgopen bool) *gin.Engine {
	if mode == "release" {
		gin.SetMode(gin.ReleaseMode)
	}
	r := gin.New()
	r.Use(logger.GinLogger(), logger.GinRecovery(true), middlewares.Cors())

	v1 := r.Group("/api/v1")
	{
		user := v1.Group("/userapi")
		{
			user.POST("/login", api.UserLoginHandler)
			user.POST("/regist", api.UserRegistHandler)
			user.POST("/addrole", api.UserAddRoleHandler)

			user.GET("/userinfo", middlewares.JWTUserAuthMiddleware(), api.UserGetUserInfoHandler)
		}
	}
	if sgopen {
		r.GET("/swagger/*any", gs.WrapHandler(swaggerfiles.Handler))
	}
	return r
}
